package cn.com.oyat.idea.service.impl;

import cn.com.oyat.idea.model.User;
import cn.com.oyat.idea.mapper.TUserMapper;
import cn.com.oyat.idea.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fuce
 * @since 2025-02-20
 */
@Service
@RequiredArgsConstructor
public class UserServiceImpl extends ServiceImpl<TUserMapper, User> implements IUserService {

    private final TUserMapper baseMapper;

    /**
     * 分页查询
     */
    @Override
    public IPage<User> queryPageList(Page<User> pageParam,User vo) {
        LambdaQueryWrapper<User> lqw = buildQueryWrapper(vo);
       return baseMapper.selectPage(pageParam,lqw);
    }

    private LambdaQueryWrapper<User> buildQueryWrapper(User vo) {
        LambdaQueryWrapper<User> lqw = Wrappers.lambdaQuery();
            lqw.eq(vo.getId() != null, User::getId, vo.getId());
            lqw.eq(vo.getUsername() != null, User::getUsername, vo.getUsername());
            lqw.eq(vo.getPassword() != null, User::getPassword, vo.getPassword());
            lqw.eq(vo.getCreatedAt () != null, User::getCreatedAt , vo.getCreatedAt ());


        return lqw;
    }
}
